<?php
require_once 'DBConnecter.inc';
class Employee extends DBConnecter {
	public $mem_id = "";
	public $passwd = "";
	public $mem_nm = "";
	public $cusno = "";
	public $ds_number = "";
	public $truck_id = "";
	public $seo_no = "";
	public $seo_open_dt = "";
	public $in_bogo = "";
	public $mem_grade = "";
	public $enter_dt = "";
	public $retire_dt = "";
	public $position = "";
	public $sply_dt = "";
	public $bank_nm = "";
	public $act_nm = "";
	public $actno = "";
	public $email = "";
	public $address = "";
	public $comm_dist = "";
	public $comm_time = "";
	public $gps_id = "";
	public $insu_deg = "";
	public $insu_amt = "";
	public $cusm_cd = "";
	public $car_id = "";
	public $phone_number = "";
	public $fare_amt = "";
	public $instl_fee = "";
	public $instl_deg = "";
	public $direct_tp = "";
	public $car_soyu_tp = "";
	public $brno = "";
	public $mng_amt = "";
	public $org_amt = "";
	public $gps_amt = "";
	public $dependent_count = "";
	public $time_wages = "";
	public $base_pay = "";
	public $extension_pay = "";
	public $annual_pay = "";
	public $early_slot = "";
	public $commit_pay = "";
	public $meal_pay = "";
	public $pension_fee = "";
	public $insurance_fee = "";
	public $recuperation_fee = "";
	public $unemploy_insurance_fee = "";
	public $income_tax = "";
	public $city_tax = "";
	
	function __construct() {
		$this->connectDB ();
		// $this->selectDB ( 'devdog' );
	}
	public function tablePrint($isSuperAdmin) {
		if ($isSuperAdmin) {
			echo "<tr onclick=\"location.href='./employee_detail.php?pageType=2&id=" . $this->mem_id . "'\">";
		} else {
			echo "<tr onclick=\"location.href='./daily_report.php?id=" . $this->mem_id . "'\">";
		}
		
		echo "<td>" . $this->mem_id . "</td>";
		// echo "<td>" . $this->passwd . "</td>";
		echo "<td>" . $this->mem_nm . "</td>";
		// echo "<td>" . $this->cusno . "</td>";
		echo "<td>" . $this->ds_number . "</td>";
		echo "<td>" . $this->truck_id . "</td>";
		echo "<td>" . $this->seo_no . "</td>";
		echo "<td>" . $this->mem_grade . "</td>";
		// echo "<td>" . $this->enter_dt . "</td>";
		// echo "<td>" . $this->retire_dt . "</td>";
		echo "<td>" . $this->position . "</td>";
		echo "<td>" . $this->sply_dt . "</td>";
		// echo "<td>" . $this->bank_nm . "</td>";
		// echo "<td>" . $this->act_nm . "</td>";
		// echo "<td>" . $this->actno . "</td>";
		echo "<td>" . $this->email . "</td>";
		echo "<td>" . $this->address . "</td>";
		// echo "<td>" . $this->comm_dist . "</td>";
		// echo "<td>" . $this->comm_time . "</td>";
		// echo "<td>" . $this->gps_id . "</td>";
		// echo "<td>" . $this->insu_deg . "</td>";
		// echo "<td>" . $this->insu_amt . "</td>";
		// echo "<td>" . $this->cus_nm . "</td>";
		echo "<td>" . $this->car_id . "</td>";
		echo "<td>" . $this->phone_number . "</td>";
		echo "<td>" . Number_Format ( $this->fare_amt ) . "</td>";
		// echo "<td>" . $this->instl_fee . "</td>";
		// echo "<td>" . $this->direct_tp . "</td>";
		echo "</tr>";
	}
	public function search4table($isSuperAdmin, $table, $category, $value) {
		$sql = "CALL ".self::CONST_DB.".search('" . $table . "','" . $category . "','" . $value . "', '', '');select @out_err_cd, @out_err_msg;";
		$retval = array ();
		
		if ($rs = $this->getMySqlConneter ()->multi_query ( $sql )) {
			if ($rs != null && $rs = $this->getMySqlConneter ()->use_result ()) {
				while ( $row = $rs->fetch_row () ) {
					$this->mem_id = $row ['0']; // 사번
					$this->mem_nm = $row ['1']; // 성명
					$this->ds_number = $row ['2']; // 면허번호
					$this->truck_id = $row ['3']; // 화물종사자자격번호
					$this->seo_no = $row ['4']; // 사업자등록번호
					$this->mem_grade = $row ['5']; // 회원등급
					$this->position = $row ['6']; // 직책
					$this->sply_dt = $row ['7']; // 급여일
					$this->email = $row ['8']; // 이메일
					$this->address = $row ['9']; // 주소
					$this->cusm_cd = $row ['10']; // 거래처이름
					$this->car_id = $row ['11']; // 차량번호
					$this->phone_number = $row ['12']; // 연락처
					$this->fare_amt = $row ['13']; // 기본운송료
					$this->direct_tp = $row ['14']; // 직영구분
					                                
					// $retval [] = $article;
					
					$this->tablePrint ( $isSuperAdmin );
				}
				$rs->free ();
			}
			// if ($this->getMySqlConneter ()->more_results ()) {
			// if ($this->getMySqlConneter ()->next_result ()) {
			// $rs = $this->getMySqlConneter ()->store_result ();
			// if ($rs != null) {
			// $err_param = $rs->fetch_row ();
			// echo "[" . $err_param [0] . "]";
			// echo "[" . $err_param [1] . "]";
			// }
			// }
			// }
			// $this->getMySqlConneter ()->next_result ();
			// if ($this->getMySqlConneter ()->more_results ()) {
			// if ($this->getMySqlConneter ()->next_result ()) {
			// $rs = $this->getMySqlConneter ()->store_result ();
			// if ($rs != null) {
			// $err_param2 = $rs->fetch_row ();
			// echo "[" . $err_param2 [0] . "]";
			// echo "[" . $err_param2 [1] . "]";
			// }
			// }
			// }
		}
		// return $retval;
	}
	public function search4Detail($value) {
		$sql = "CALL ".self::CONST_DB.".search('5','1','" . $value . "', '', '');select @out_err_cd, @out_err_msg;";
		$retval = array ();
		 
		if ($rs = $this->getMySqlConneter ()->multi_query ( $sql )) {
			if ($rs != null && $rs = $this->getMySqlConneter ()->use_result ()) {
				while ( $row = $rs->fetch_row () ) {
					$this->mem_id = $row ['0'];
					$this->passwd = $row ['1'];
					$this->mem_nm = $row ['2'];
					$this->cusno = $row ['3'];
					$this->ds_number = $row ['4'];
					$this->truck_id = $row ['5'];
					$this->seo_no = $row ['6'];
					$this->seo_open_dt = $row ['7'];
					$this->in_bogo = $row ['8'];
					$this->mem_grade = $row ['9'];
					$this->enter_dt = $row ['10'];
					$this->retire_dt = $row ['11'];
					$this->position = $row ['12'];
					$this->sply_dt = $row ['13'];
					$this->bank_nm = $row ['14'];
					$this->act_nm = $row ['15'];
					$this->actno = $row ['16'];
					$this->email = $row ['17'];
					$this->address = $row ['18'];
					$this->comm_dist = $row ['19'];
					$this->comm_time = $row ['20'];
					$this->gps_id = $row ['21'];
					$this->insu_deg = $row ['22'];
					$this->insu_amt = $row ['23'];
					$this->cusm_cd = $row ['24'];
					$this->car_id = $row ['25'];
					$this->phone_number = $row ['26'];
					$this->fare_amt = $row ['27'];
					$this->instl_fee = $row ['28'];
					$this->instl_deg = $row ['29'];
					$this->direct_tp = $row ['30'];
					$this->car_soyu_tp = $row ['31'];
					$this->brno = $row ['32'];
					$this->mng_amt = $row ['33'];
					$this->org_amt = $row ['34'];
					$this->gps_amt = $row ['35'];
					$this->dependent_count = $row ['36'];
					$this->time_wages = $row ['37'];
					$this->base_pay = $row ['38'];
					$this->extension_pay = $row ['39'];
					$this->annual_pay = $row ['40'];
					$this->early_slot = $row ['41'];
					$this->commit_pay = $row ['42'];
					$this->meal_pay = $row ['43'];
					$this->pension_fee = $row ['44'];
					$this->insurance_fee = $row ['45'];
					$this->recuperation_fee = $row ['46'];
					$this->unemploy_insurance_fee = $row ['47'];
					$this->income_tax = $row ['48'];
					$this->city_tax = $row ['49'];
				}
				$rs->free ();
			}
		}
	}

	public function createEmployee($passwd, $mem_nm, $cusno, $ds_number, $truck_id, $seo_no, $seo_open_dt, $in_bogo, $mem_grade, $enter_dt, $retire_dt, $position, $sply_dt, $bank_nm, $act_nm, $actno, $email, $address, $comm_dist, $comm_time, $gps_id, $insu_deg, $insu_amt, $cusm_cd, $car_id, $phone_number, $fare_amt, $instl_fee, $instl_deg, $direct_tp, $car_soyu_tp, $brno, $mng_amt, $org_amt, $gps_amt, $dependent_count, $time_wages, $base_pay, $extension_pay, $annual_pay, $early_slot, $commit_pay, $meal_pay, $pension_fee, $insurance_fee, $recuperation_fee, $unemploy_insurance_fee, $income_tax, $city_tax) {
		$sql = "CALL ".self::CONST_DB.".mem_insert('" . $passwd . "','" . $mem_nm . "','" . $cusno . "','" . $ds_number . "','" . $truck_id . "','" . $seo_no . "','" . $seo_open_dt . "','" . $in_bogo . "','" . $mem_grade . "','" . $enter_dt . "','" . $retire_dt . "','" . $position . "','" . $sply_dt . "','" . $bank_nm . "','" . $act_nm . "','" . $actno . "','" . $email . "','" . $address . "','" . $comm_dist . "','" . $comm_time . "','" . $gps_id . "','" . $insu_deg . "','" . $insu_amt . "','" . $cusm_cd . "','" . $car_id . "','" . $phone_number . "','" . $fare_amt . "','" . $instl_fee . "','" . $instl_deg . "','" . $direct_tp . "','" .$car_soyu_tp . "','" .$brno . "','" .$mng_amt . "','" .$org_amt . "','" .$gps_amt . "','" .$dependent_count . "','" .$time_wages . "','" .$base_pay . "','" .$extension_pay . "','" .$annual_pay . "','" .$early_slot . "','" .$commit_pay . "','" .$meal_pay . "','" .$pension_fee . "','" .$insurance_fee . "','" .$recuperation_fee . "','" .$unemploy_insurance_fee . "','" .$income_tax . "','" .$city_tax . "');select @out_err_cd, @out_err_msg;";
//  		echo $sql;
		$rs = $this->getMySqlConneter ()->multi_query ( $sql );
	}

	public function modifyEmployee($mem_id, $passwd, $mem_nm, $cusno, $ds_number, $truck_id, $seo_no, $seo_open_dt, $in_bogo, $mem_grade, $enter_dt, $retire_dt, $position, $sply_dt, $bank_nm, $act_nm, $actno, $email, $address, $comm_dist, $comm_time, $gps_id, $insu_deg, $insu_amt, $cusm_cd, $car_id, $phone_number, $fare_amt, $instl_fee, $instl_deg, $direct_tp , $car_soyu_tp, $brno, $mng_amt, $org_amt, $gps_amt, $dependent_count, $time_wages, $base_pay, $extension_pay, $annual_pay, $early_slot, $commit_pay, $meal_pay, $pension_fee, $insurance_fee, $recuperation_fee, $unemploy_insurance_fee, $income_tax, $city_tax) {
		$sql = "CALL ".self::CONST_DB.".mem_update('" . $mem_id . "','" . $passwd . "','" . $mem_nm . "','" . $cusno . "','" . $ds_number . "','" . $truck_id . "','" . $seo_no . "','" . $seo_open_dt . "','" . $in_bogo . "','" . $mem_grade . "','" . $enter_dt . "','" . $retire_dt . "','" . $position . "','" . $sply_dt . "','" . $bank_nm . "','" . $act_nm . "','" . $actno . "','" . $email . "','" . $address . "','" . $comm_dist . "','" . $comm_time . "','" . $gps_id . "','" . $insu_deg . "','" . $insu_amt . "','" . $cusm_cd . "','" . $car_id . "','" . $phone_number . "','" . $fare_amt . "','" . $instl_fee . "','" . $instl_deg . "','" . $direct_tp . "','" .$car_soyu_tp . "','" .$brno . "','" .$mng_amt . "','" .$org_amt . "','" .$gps_amt . "','" .$dependent_count . "','" .$time_wages . "','" .$base_pay . "','" .$extension_pay . "','" .$annual_pay . "','" .$early_slot . "','" .$commit_pay . "','" .$meal_pay . "','" .$pension_fee . "','" .$insurance_fee . "','" .$recuperation_fee . "','" .$unemploy_insurance_fee . "','" .$income_tax . "','" .$city_tax . "');select @out_err_cd, @out_err_msg;";
//  		echo $sql;
		$rs = $this->getMySqlConneter ()->multi_query ( $sql );
	}
	public function getSplyDate($mem_id) {
		$query = "select ".self::CONST_DB.".get_sply_dt('" . $mem_id . "');";
		$result = $this->query ( $query );
		
		if (! empty ( $result )) {
			$row = mysqli_fetch_row ( $result );
			if (! empty ( $row )) {
				$reVal = $row [0];
				$result->free ();
				return $reVal;
			}
		} 
		$result->free ();
	}
}